<template>
    <div class="logo">
        <img src="../assets/bj.png" alt="" style="width:100%;height:5.5rem">
        <div class="logo-content">
            <div class="border">
                <img class="img" slot="label"  src="@/assets/account.png">
                <input class="input" type="text" v-model="account"  placeholder="请输入账号">
            </div> 
            <div class="border">
                <img class="img" slot="label"  src="@/assets/password.png">
                <input class="input" v-model="password" type="password" placeholder="请输入密码">
            </div> 
            <flexbox>
                <x-button @click.native="_login">登录</x-button>
            </flexbox>   
        </div>  
        <toast v-model="showPositionValue" type="text" :text="text"></toast>          
    </div>
</template>

<script>
import { XInput, XButton, Flexbox, Alert, Toast } from "vux";
import axiosConfig from "@/service/axiosConfig";
export default {
  components: {
    XInput,
    XButton,
    Flexbox,
    Alert,
    Toast
  },
  data() {
    return {
      account: "",
      password: "",
      userInfo: {},
      showPositionValue: false,
      text: "",
      id: "",
      loginId: 1 //从浏览器入口进来存变量
    };
  },
  created() {
    // localStorage.removeItem('token');
  },
  methods: {
    _login() {
      const data = {
        account: this.account,
        password: this.password,
        login_ip: "string"
      };
      if (!this.account) {
        this.text = "请输入账号";
        this.showPositionValue = true;
        return false;
      }
      if (!this.password) {
        this.text = "请输入密码";
        this.showPositionValue = true;
        return false;
      }
      //this.$router.push('/index')
      this.$axios.post("/system/login", data).then(res => {
         console.log(res.data);
        if (res.data.errCode == 0) {
          this.userInfo = res.data.userInfo;
          let token = res.data.token;
          localStorage.setItem("userInfo", JSON.stringify(this.userInfo));
          sessionStorage.setItem("token", token);
          localStorage.setItem("errCode", res.data.errCode);
          localStorage.setItem("id", res.data.userInfo.id);
          localStorage.setItem("companyId", res.data.userInfo.company);
          sessionStorage.setItem("loginId", this.loginId);
          // this.$router.push({ path: "/index" });
          window.location.href = '/index'
          this.$router.push('/index')
         
        } else {
          this.$vux.alert.show({
            content: "账号或密码错误",
            hideOnBlur: true,
            maskZIndex: 100
          });
        }
      });
    }
  }
};
</script>
<style scoped lang="less">
.logo {
  .logo-content {
    width: 90%;
    margin: 0 auto;
    padding: 0.6rem 0.4rem 1rem;
    background: #fff;
    border-radius: 0.2rem;
    box-shadow: 0px 5px 5px rgba(201, 119, 201, 0.1);
    position: absolute;
    left: 5%;
    top: 3.36rem;
    font-size: 0.3rem;
    color: #bfbfbf;
    .input {
      width: 5.5rem;
    }
    .border {
      border-bottom: 1px solid #f0f0f0;
      margin-bottom: 0.4rem;
      //   padding-left: .3rem;
      .img {
        width: 0.27rem;
        height: 0.3rem;
        margin-right: 0.05rem;
      }
    }
    .vux-flex-row {
      margin-top: 0.9rem;
    }
  }
  .weui-cell__bd .weui-input {
    color: #000000;
  }
}
.vux-flex-row {
  margin-top: 0.9rem;
}

// .weui-cell {
//   padding: 10px 15px !important;
// }
</style>